import datetime

import jwt

from djangoProject1.settings.dev import SECRET_KEY
key = SECRET_KEY
class MyJWT():
    def getToken(self,user_id,user_name):
        user={
            "id":user_id,
            "username":user_name,
            'exp':datetime.datetime.now()+datetime.timedelta(hours=2)
        }

        return "Bearer "+jwt.encode(user,key,algorithm="HS256")
    def Checktoken(self,token):
        if token:
                return jwt.decode(token,key,algorithms=['HS256'])

myjwt = MyJWT()
print(myjwt.getToken(1,"张三"))
